'use strict'

const getLastClueDate = async () => {
    let response = await $.ajax('/admin/auth/last-clue');

    if (response.status) {
        let date = response.data['last-date'];
        console.log("date", date);
        localStorage.setItem('__clue_last_date', date);
        return date;
    }
    if (response.redirect) {
        location.href = response.redirect;
    }

}

const checkLastClueDate = async (diff = true) => {
    let preDate = localStorage.getItem('__clue_last_date');
    let nowDate = await getLastClueDate();
    if (diff)
        if (preDate && nowDate) {
            if (dayjs(preDate).isBefore(dayjs(nowDate))) {
                Dcat.swal.fire({
                    title: '有新的线索',
                    confirmButtonText: '去查看',
                    cancelButtonText: '我知道了,关闭',
                }).then((result) => {
                    checkLastClueDate();
                    if (result.isConfirmed) {
                        window.location.href = '/admin/clues/user';
                    }
                })
                return;
            }
        }

    setTimeout(function () {
        checkLastClueDate();
    }, 10 * 1000);
}


checkLastClueDate(false);

